<template>
  <div class="clearfix table-out">
    <div class="clearfix out-con pos-rel">
      <el-button
        type="primary"
        plain
        size="small"
        class="return pointer"
        @click="returnGo"
        ><i class="iconfont icon-fanhui"></i> 返回
      </el-button>
      <top-step ref="topStepRef"></top-step>
      <div class="clear h20"></div>
      <form-data ref="formDataRef" @getPdf="getPdf"></form-data>
      <div class="but-out clearfix" v-if="!btnShow">
        <el-button type="primary" @click="submit(1,1)" class="submit-big two" v-if="saisjc!='1779359204496863233'"
          >暂存</el-button
        >
        <el-button type="primary" @click="apply()" class="submit-big two"  v-if="saisjc!='1779359204496863233'"
          >提交</el-button
        >
        <el-button type="primary" @click="submit(1,2)" class="submit-big two" v-if="saisjc=='1779359204496863233'"
        >提交视频</el-button
        >
      </div>
      <form-data-pdf
        v-show="pdfStatic"
        :pdfTitle="pdfTitle"
        :pdf-title-sub="pdfTitleSub"
        :form-data="pdfData"
        ref="formDataPdfRef"
      ></form-data-pdf>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import pubJs from "./pub";

export default {
  mixins: [pubJs],

  data() {
    return {
      zoupId: null,
      saisjc: null,
      saisId: null,
      pdfData: [],
      pdfParams: {},
      pdfStatic: false,
      pdfTitle: "",
      pdfTitleSub: "",
      btnShow: true,
    };
  },

  inject: ["imageUrl", "serviceUrl"],

  async mounted() {
    this.saisqyId = this.$route.query.saisqyId;
    this.saisjc = this.$route.query.saisjc;
    this.zoupId = this.$route.query.id;
    this.saisId = this.$route.query.saisId;

    let params = {
      saisjc: this.saisjc,
      canszpId: this.zoupId,
      saisId: this.saisId,
    };

    await this.$refs["formDataRef"].getFormDefine(params, "zuopxq");
    this.$refs["formDataRef"].getFormData(params, "zuopxq");
    this.$refs["topStepRef"].getList(params, "zuopxq");
    this.btnShow = this.$refs["formDataRef"].disabled;

    if (localStorage.getItem("topStepId") == "1779359204496863233") {
      this.btnShow = false;
    }
    console.log(this.btnShow, " this.btnShow");
  },

  methods: {
    apply() {
      this.$refs["formDataRef"].$refs["ruleForm"].validate((valid) => {
        let that = this;
        const config = {
          headers: {
            "X-Access-Token": localStorage.getItem("token"),
          },
        };
        let _formData = that.$refs["formDataRef"].formData;
        // 修改作品状态
        _formData.zuopzt = 1;
        _formData.saisqyId = that.saisqyId;
        if (valid) {
          axios
              .post(
                  that.serviceUrl + "/saisjczd2/cbda2Saisjczd/genZilshData",
                  { data: JSON.stringify(_formData) },
                  config
              )
              .then((resp) => {
                console.log(resp);
                if (resp.data.success) {
                  that.$message.success("提交成功");
                  that.$router.push("/pc/myWork?saisId=" + this.saisId);
                } else that.$message.warning(resp.data.message);
              })
              .catch((error) => {
                this.$message.warning(error);
                //console.log(error);
              });
        } else {
          this.$message.warning("必填项未完成！");
        }
      });
      

    },

    submit(num,type) {
      let that = this;
      const config = {
        headers: {
          "X-Access-Token": localStorage.getItem("token"),
        },
      };
      let _formData = that.$refs["formDataRef"].formData;
      // 修改作品状态
      if(type==1){
        _formData.zuopzt = 0;
      }
      if(this.saisjc =='1779359204496863233'){//半决赛
        _formData.isDeleteZilshAndPings = false
      }else{
        _formData.isDeleteZilshAndPings = true
      }
      
      axios
        .put(
          that.serviceUrl + "/saisjczd2/cbda2Saisjczd/editFormData",
          { data: JSON.stringify(_formData) },
          config
        )
        .then((resp) => {
          console.log(resp);
          if (resp.data.success) {
            this.pdfParams = resp.data.result;
            if (num == 1) {
              that.$message.success(this.saisjc =='1779359204496863233'?'保存视频成功！':"暂存成功！");
              if(this.saisjc =='1779359204496863233'){
                that.$router.push("/pc/myWork?saisId=" + this.saisId);
              }
            } else {
              this.zuopinExportPdf(resp.data.result);
            }
          } else {
            that.$message.error(resp.data.message);
          }
        })
        .catch((error) => {
          this.$message.warning(error);
          //console.log(error);
        });
    },
    returnGo() {
      this.$router.go(-1); // 返回上一个页面
    },
  },
};
</script>

<style scoped lang="less"></style>
